<?php
namespace app\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\View;

class Index extends BaseController
{
    public $index_back = 'http://admin.gxdati.com/storage/default/index_back.png';
    public function index(){
        error_404();
    }

    public function active(){
        //地址栏获取学校简写
        $school_abbr = input('school_abbr');
        $school = Db::table('active_school')->where('school_abbr',$school_abbr)->find();
        if(empty($school)||$school['status']!=1){
            error_404();
        }
        if(empty($school['index_back'])){
            $school['index_back'] = $this->index_back;
        }

        View::assign([
            'school'  => $school
        ]);
        // 模板输出
        return View::fetch();
    }


    public function apply(){
        //地址栏获取学校简写
        $school_abbr = input('school_abbr');
        $school = Db::table('active_school')->where('school_abbr',$school_abbr)->find();
        if(empty($school)||$school['status']!=1){
            error_404();
        }
        View::assign([
            'school'  => $school
        ]);
        //
        return View::fetch();
    }


    public function question(){
        $school_abbr = input('school_abbr');
        $school = Db::table('active_school')->where('school_abbr',$school_abbr)->find();
        if(empty($school)||$school['status']!=1){
            error_404();
        }
        $videos = Db::table('active_video')->where('status',1)->select()->toArray();
        $count = count($videos);

        $page = intval(input('get.page',1));
        $page < 1 and $page = 1;
        $page > $count and $page = $count;

        View::assign([
            'count' => $count,
            'page' => $page,
            'school' => $school,
            'videos' => $videos
        ]);
        return View::fetch();
    }


    public function submit(){

        return View::fetch();
    }

}
